package com.hcy.rabbitmanagerapi.controller;

import com.hcy.common.dto.response.CallCarConfigDTO;
import com.hcy.common.dto.response.GaoDeGfidsResponseDTO;
import com.hcy.commonn.CommonInfoClient;
import com.hcy.rabbitbasicmodel.dto.MyPage;
import com.hcy.rabbitbasicmodel.model.ResponseData;
import com.hcy.rabbitbasicmodel.model.ReturnResult;
import com.hcy.rabbitbasicmodel.signl.Add;
import com.hcy.rabbitbasicmodel.signl.Delete;
import com.hcy.userclient.client.UserInfoClient;
import com.hcy.usermodel.dto.OptLogDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author huchenying
 * @Description
 * @Date 2022/5/12
 **/
@RestController
@RequestMapping("/operator")
@Slf4j
public class OperatorController {

    @Autowired
    CommonInfoClient commonInfoClient;
    @Autowired
    UserInfoClient userInfoClient;

    /**
     * -------------------------- 叫车策略 ------------------------------
     */

    /**
     * @Author huchenying
     * @Description  获取叫车策略配置list
     * @Date 2022/5/12 23:46
     **/
    @PostMapping("/getCallConfigList")
    public ReturnResult getCallConfigList(){
        ResponseData<List<CallCarConfigDTO>> callConfigList = commonInfoClient.getCallConfigList();
        if(callConfigList.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(callConfigList.getData());
    }


    /**
     * @Author huchenying
     * @Description  添加或更新叫车策略
     * @Date 2022/5/12 23:46
     **/
    @PostMapping("/insertOrUpdateCallConfig")
    public ReturnResult insertOrUpdateCallConfig(@Validated(Add.class) @RequestBody CallCarConfigDTO callCarConfigDTO){
        ResponseData<CallCarConfigDTO> responseData = commonInfoClient.insertOrUpdateCallConfig(callCarConfigDTO);
        if(responseData.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(responseData.getData());
    }

    /**
     * @Author huchenying
     * @Description  删除叫车策略
     * @Date 2022/5/12 23:46
     **/
    @PostMapping("/deleteCallConfig")
    public ReturnResult deleteCallConfig(@Validated(Delete.class) @RequestBody CallCarConfigDTO callCarConfigDTO){
        ResponseData<Object> responseData = commonInfoClient.deleteCallConfig(callCarConfigDTO);
        if(responseData.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(responseData.getData());
    }

    /**
     * -------------------------- 区域配置 ------------------------------
     */

    /**
     * @Author huchenying
     * @Description  获取区域配置list
     * @Date 2022/5/12 23:49
     **/
    @PostMapping("/getGridConfig")
    public ReturnResult getGridConfig(){
        ResponseData<List<GaoDeGfidsResponseDTO>> gridConfig = commonInfoClient.getGridConfig();
        if(gridConfig.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(gridConfig.getData());
    }

    /**
     * @Author huchenying
     * @Description  添加更新区域配置
     * @Date 2022/5/12 23:50
     **/
    @PostMapping("/insertOrUpdateGridConfig")
    public ReturnResult insertOrUpdateGridConfig(@Validated(Add.class) @RequestBody GaoDeGfidsResponseDTO gaodeGfids){
        ResponseData<GaoDeGfidsResponseDTO> gaoDeGfidsResponseDTOResponseData = commonInfoClient.insertOrUpdateGridConfig(gaodeGfids);
        if(gaoDeGfidsResponseDTOResponseData.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(gaoDeGfidsResponseDTOResponseData.getData());
    }

    /**
     * @Author huchenying
     * @Description  删除区域配置
     * @Date 2022/5/12 23:50
     **/
    @PostMapping("/deleteGridConfig")
    public ReturnResult deleteGridConfig(@Validated(Delete.class) @RequestBody GaoDeGfidsResponseDTO gaodeGfids){
        ResponseData<Object> responseData = commonInfoClient.deleteGridConfig(gaodeGfids);
        if(responseData.getCode().noSuccess()){
            return ReturnResult.fail("操作失败");
        }
        return ReturnResult.success(responseData.getData());
    }


    /**
     * -------------------------- 价格配置 ------------------------------
     */

    /**
     * @Author huchenying
     * @Description  获取价格配置
     * @Date 2022/5/12 23:51
     **/
    @PostMapping("/getPriceConfig")
    public ReturnResult getPriceConfig(){

        return ReturnResult.success();
    }

    /**
     * @Author huchenying
     * @Description  更新价格配置
     * @Date 2022/5/12 23:51
     **/
    @PostMapping("/updatePriceConfig")
    public ReturnResult updatePriceConfig(){

        return ReturnResult.success();
    }

    /**
     * @Author huchenying
     * @Description  查询操作日志
     * @Date 2022/5/13 21:58
     **/
    @PostMapping("/getOptLogList")
    public ReturnResult getOptLogList(@Validated @RequestBody OptLogDTO request){
        ResponseData<MyPage<OptLogDTO>> optLogList = userInfoClient.getOptLogList(request);
        if(optLogList.getCode().noSuccess()){
            return ReturnResult.fail("获取失败");
        }
        return ReturnResult.success(optLogList.getData());
    }
}
